package com.woniuxy.caradmin.controller;


import com.woniuxy.caradmin.entity.pojo.Oilrecord;
import com.woniuxy.caradmin.exception.CarException;
import com.woniuxy.caradmin.service.OilrecordService;
import com.woniuxy.caradmin.util.Constaint;
import com.woniuxy.caradmin.util.R;
import com.woniuxy.caradmin.util.ResultCode;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author womenzu
 * @since 2020-12-07
 */
@RestController
@Slf4j
@RequestMapping("/oilrecord")
public class OilrecordController {
    @Autowired
    private OilrecordService oilrecordService;

    @ApiOperation("查询全部加油记录")
    @GetMapping(value = "/findAllOilRecords")
    public R findAllOilRecords() {
        List<Oilrecord> oilrecordList = oilrecordService.selectAllOilRecords();
        if (oilrecordList != null && oilrecordList.size() > 0) {
            return R.ok().data("oilrecordList", oilrecordList);
        } else {
            throw new CarException(ResultCode.OILRECORDFAIL, Constaint.OILRECORDFAIL);
        }
    }
}

